package com.itlong.cloud.app;

import com.itlong.cloud.noncore.commons.ITimeTaskOfOperationLogServiceClient;
import com.itlong.cloud.user.app.IAppRegisterServiceClient;
import com.itlong.cloud.utils.date.DateUtil;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;

/**
 * <desc>
 *      App用户Token自动延期
 * </desc>
 *
 * @createDate 2018/1/18
 */
@EnableScheduling // 启用定时任务
@RestController
public class AppUserTokenTimeTask {
    private static Logger LOG = LoggerFactory.getLogger(AppUserTokenTimeTask.class);

    @Autowired
    private IAppRegisterServiceClient iAppRegisterServiceClient;
    @Autowired
    private ITimeTaskOfOperationLogServiceClient iTimeTaskOfOperationLogServiceClient;



    /**
     * <desc>
     *     根据APP端用户的操作日志来自动更新用户Token缓存
     * </desc>
     * @return
     * @author cuiduanwu
     * @createDate 2018/1/18
     */
    @Scheduled(cron = "0 0 2 * * ?") // 每天凌晨2点执行
    public void timeTaskSychro() {
        try {
            long begin = System.currentTimeMillis();
            iAppRegisterServiceClient.timeTaskOfUserTokenUpdate();
            long endToken = System.currentTimeMillis();
//            LOG.info("【定时任务】根据APP端用户的操作日志更新用户Token缓存执行成功，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss")+"-耗时:"+(endToken-begin) / 1000 +"秒");

            iTimeTaskOfOperationLogServiceClient.timTaskOfOperationLogProcess();
            long endLog = System.currentTimeMillis();
//            LOG.info("【定时任务】系统操作日志定时转移至冷表数据执行成功，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss")+"-耗时:"+(endLog-endToken) / 1000 +"秒");
        }catch (Exception e){
            LOG.error("【定时任务】根据APP端用户的操作日志更新用户Token缓存执行失败，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss:"),e);
        }
    }



}
